package GUI;

import java.awt.*;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import DataObjects.AreYouSure;
import Messages.MessageAddNewSupplier;
import Messages.MessageDeleteSupplier;
import Messages.MessageGetSupplierById;
import Messages.MessageGetSupplierByIdReply;
import Messages.MessageGetUserById;
import Messages.MessageGetUserByIdReply;
import Messages.MessageShowAllSuppliers;
import Messages.MessageShowAllSuppliersReply;

public class PanelFunctionSupplierThis extends PanelFunctionsEmpty {

	private static final long serialVersionUID = 1L;
	private MainMenu mainMenu;
	private Vector<String> supplier;
	private Vector<Vector> suppliers;
	private JButton button_editSupplier;
	private JButton button_DeletSupplier;
	private JButton button_add_item;
	private JButton button_dohotEmployee;
	private AreYouSure areyousure;
	private Integer answerDelSupp=0;
	String IDSupp;
	
	// the supplier is ordered by suppID,suppName,suppPhoneNo,suppPhoneNo2,suppCellNo,suppMail,suppFax,suppContactMen,suppZipCode,suppCity,suppHouse,suppStreet

public PanelFunctionSupplierThis(MainMenu mm,Vector <String> supp)
{
	super();
	this.supplier=supp;
	this.mainMenu=mm;
	this.add(get_button_editSupplier());
	this.add(get_button_DeletSupplier(supplier));
	this.add(get_button_add_item());
//	this.add(get_button_delitEmployee());
//	this.add(button_dohotEmployee());
	
	
	}
	
	
private JButton get_button_add_item() 
{
	if (button_add_item == null) 
	{			
		button_add_item=new JButton("להוסיף פריטים לספק");  			 
		button_add_item.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_add_item.setPreferredSize(new Dimension(220, 30));
		
		button_add_item.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
				mainMenu.getContentPane().add(new PfAdd_items_to_supplier(mainMenu,supplier.get(0)), BorderLayout.CENTER);	
				mainMenu.getContentPane().add(new PanelFunctionEmptyWithoutKeyboard(mainMenu), BorderLayout.EAST);
				mainMenu.getContentPane().validate();						
			}
		});
	}
	return button_add_item;
}





	
	
private JButton get_button_editSupplier() 
	{
		if (button_editSupplier == null) 
		{			
			button_editSupplier=new JButton("לעדכן  פרטי ספק");  			 
			button_editSupplier.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_editSupplier.setPreferredSize(new Dimension(220, 30));
			
			button_editSupplier.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					MessageGetSupplierById getUser=new MessageGetSupplierById(supplier.get(0));
					try {
						mainMenu.ms.client.sendToServer(getUser);	
					    MessageGetSupplierByIdReply result=(MessageGetSupplierByIdReply)mainMenu.ms.client.GetMessage();
					    mainMenu.getContentPane().add(new PfUpdate_supplier(mainMenu,result.getSupplier()), BorderLayout.CENTER);
					    mainMenu.getContentPane().validate();
					    }	
					catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				
				}
			});
			
			
		}
		return button_editSupplier ;
	}
	
	
	
	
private JButton get_button_DeletSupplier(final Vector<String> sup) 
	{
		if (button_DeletSupplier == null) 
		{			
			button_DeletSupplier=new JButton("למחוק ספק");  			 
			button_DeletSupplier.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_DeletSupplier.setPreferredSize(new Dimension(220, 30));
			
			button_DeletSupplier.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					
					
					int n = JOptionPane.showConfirmDialog(
						    null,
						    "    אתה בטוח?",
						    "    בקשת אישור  ",
						    JOptionPane.YES_NO_OPTION);
					 //Object selectedValue = pane.getValue();
					 if(n==1){
						 
					 }
					 else{
						IDSupp= sup.get(0);
						MessageDeleteSupplier msgDelSupp=new MessageDeleteSupplier (IDSupp);
						try {
							mainMenu.ms.client.sendToServer(msgDelSupp);
							mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
							MessageShowAllSuppliers msgShowSupp=new MessageShowAllSuppliers( );
							mainMenu.ms.client.sendToServer(msgShowSupp);
							MessageShowAllSuppliersReply resultSupp=(MessageShowAllSuppliersReply)mainMenu.ms.client.GetMessage();
							mainMenu.getContentPane().add(new PfSearch_supplier(mainMenu,resultSupp.getResult()), BorderLayout.CENTER);	
							
							
							
							mainMenu.getContentPane().validate();
						}
						catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						
						
						
						
						}
								
								
						
					 
					
					   
				
				}}
			});
		}
		return button_DeletSupplier;
	}
	

}
